const validGangchang = (rule, value, callback, data) => {
  const { field } = rule;
  const [prop, index] = field.split("-");
  const curVal = data[index][prop];
  if (!curVal) {
    callback(new Error("请选择钢厂"));
    return;
  }
  callback();
};
const validCaizhi = (rule, value, callback, data) => {
  const { field } = rule;
  const [prop, index] = field.split("-");
  const curVal = data[index][prop];
  if (!curVal) {
    callback(new Error("请选择材质"));
    return;
  }
  callback();
};

const validPinzhong = (rule, value, callback, data) => {
  const { field } = rule;
  //console.log(rule);
  const [prop, index] = field.split("-");
  const curVal = data[index][prop];
  if (!curVal) {
    callback(new Error("请输入品种"));
    return;
  }
  callback();
};

const validguige = (rule, value, callback, data) => {
  const { field } = rule;
  //console.log(field);
  const [prop, index] = field.split("-");
  const curVal = data[index][prop];
  if (!curVal) {
    callback(new Error("请输入规格"));
    return;
  }
  callback();
};
const validJiaohuoqi = (rule, value, callback, data) => {
  const { field } = rule;
  const [prop, index] = field.split("-");
  const curVal = data[index][prop];
  if (!curVal) {
    callback(new Error("请输入交货期"));
    return;
  }
  callback();
};
const validZhidaojia = (rule, value, callback, data) => {
  const { field } = rule;
  const [prop, index] = field.split("-");
  const curVal = data[index][prop];
  if (!curVal) {
    callback(new Error("请输入指导价"));
    return;
  }
  if (!Number(curVal)) {
    callback(new Error("请输入数字值"));
  } else {
    callback();
  }
};
const validZhongliang = (rule, value, callback, data) => {
  const { field } = rule;
  const [prop, index] = field.split("-");
  const curVal = data[index][prop];
  console.log(curVal);
  if (!curVal) {
    callback(new Error("请输入重量"));
    return;
  }
  if (!Number(curVal)) {
    callback(new Error("请输入数字值"));
  } else {
    callback();
  }
};

export function tabletitle(data) {
  var columns = [
    {
      prop: "gangchang",
      label: "钢厂",
      rules: [
        {
          validator: (rule, value, callback) =>
            validGangchang(rule, value, callback, data),
          trigger: "change",
        },
      ],
      options: [
        { label: "纵横钢铁", value: "1" },
        { label: "沧州钢铁", value: "2" },
      ],
    },
    {
      prop: "caizhi",
      label: "材质",
      rules: [
        {
          validator: (rule, value, callback) =>
            validCaizhi(rule, value, callback, data),
          trigger: "change",
        },
      ],
      options: [
        { label: "热卷", value: "1" },
        { label: "冷轧", value: "2" },
      ],
    },
    {
      prop: "pinzhong",
      label: "品种",
      rules: [
        {
          validator: (rule, value, callback) =>
            validPinzhong(rule, value, callback, data),
          trigger: "blur",
        },
      ],
    },
    {
      prop: "guige",
      label: "规格",
      rules: [
        {
          validator: (rule, value, callback) =>
            validguige(rule, value, callback, data),
          trigger: "blur",
        },
      ],
    },
    {
      prop: "jiaohuoqi",
      label: "交货期",
      rules: [
        {
          validator: (rule, value, callback) =>
            validJiaohuoqi(rule, value, callback, data),
          trigger: "blur",
        },
      ],
    },
    {
      prop: "zhongliang",
      label: "重量（吨）",
      rules: [
        {
          validator: (rule, value, callback) =>
            validZhongliang(rule, value, callback, data),
          trigger: "blur",
        },
      ],
    },
    {
      prop: "zhidaojia",
      label: "指导价（元）",
      rules: [
        {
          validator: (rule, value, callback) =>
            validZhidaojia(rule, value, callback, data),
          trigger: "blur",
        },
      ],
    },
    {
      prop: "opt",
      label: "操作",
    },
  ];
  return columns;
}
